
H=5

# 递归写法
def printer(func):
    Hmax=0
    def inner(h):
        nonlocal Hmax
        Hmax=h if h>Hmax else Hmax
        Line=func(h)
        print(" "*(Hmax-len(Line))+" ".join(map(str,Line)))
        return Line
    return inner

@printer
def Pascal(h):
    if h==1: return [1]
    Lup=Pascal(h-1)
    Lup.append(0)
    return [i+j for i,j in zip(Lup,Lup[::-1])]

print("递归：")
Pascal(H)

# 动规写法
def Pascal_generator():
    L = [1]
    while True:
        yield L
        L.append(0)
        L = [i+j for i,j in zip(L,L[::-1])]

print("动规：")
for h,Line in zip(range(H),Pascal_generator()):
    print(" "*(H-h-1)+" ".join(map(str,Line)))